package hushi.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

@org.springframework.stereotype.Controller
public class Controller {
    @GetMapping("hit1")
    public String doHit1(){
//        方法一：url拼接
        return "redirect:/hit.jsp?user=admin";
    }

    @GetMapping("hit2")
    public String doHit2(RedirectAttributes attributes){
        //方法二
    //传统使用session
    //使用RedirectAttributes. (利用session原理)
    //优点: 提供了addFlashAttribute 等方法.确保数据只能被使用一次后删除
        attributes.addAttribute("user","张三");
        System.out.println(attributes);
        return "redirect:/hit.jsp";
    }

}
